@import org.silkframework.workspace.Project
@import org.silkframework.dataset.Dataset

@(project: Project, datasetName: String, dataset: Option[Dataset], title: String = "Edit Dataset")

  @widgets.pluginDialog(
    name = datasetName,
    plugins = Dataset.availablePlugins,
    currentObj = dataset,
    resources = project.resources.listRecursive,
    title = title,
    submitLabel = "Save",
    secondaryLabel = "Autoconfigure") {

    <script type="text/javascript">
      function savePlugin(pluginId, name, parameters, callbacks) {
        // Build dataset xml
        var xml = '<Dataset id=\'' + name + '\' type=\'' + pluginId + '\'>';
        for(var i in parameters) {
          xml += '  <Param name=\'' + parameters[i].name + '\' value=\'' + parameters[i].value + '\' />';
        }
        xml += '</Dataset>';

        // Submit data source
        putTask('@config.baseUrl/workspace/projects/@project.name/datasets/' + name, xml, callbacks);
      }

      function autoConfigure(pluginId, name, parameters) {
        var queryString = $.param(parameters);
        var path = '@config.baseUrl/workspace/dialogs/editDatasetAutoConfigured/@project.name/' + name + '/' + pluginId + '?' + queryString;
        closeDialog();
        showDialog(path);
      }
    </script>
  }